package com.cndongtai.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.cndongtai.dao.BaseDao;
import com.cndongtai.dao.inter.LightMapper;
import com.cndongtai.po.Light;
import com.cndongtai.vo.LightInfoBean;

@Repository("lightDao")
public class LightDao extends BaseDao implements LightMapper{

	@Override
	public List<Light> queryLightList() {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightList();
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public List<Light> queryLightListByIds(List<Integer> ids) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightListByIds(ids);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public List<Light> queryLightListByDtuId(Long dtuId) {
		
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightListByDtuId(dtuId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public boolean delLight(Integer lightId) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.delLight(lightId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public Light queryLightById(Integer lightId) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightById(lightId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public boolean addLight(Light light) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.addLight(light);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public boolean delLightByDtuId(Integer dtuId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int changeLightStateByDtuId(Long dtuId, Integer lightState) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int changeLightState(Integer lightId, Integer lightState) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.changeLightState(lightId, lightState);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return -1;
	}

	@Override
	public Light queryLightByLightNum(String lightNum) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightByLightNum(lightNum);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}
	
	@Override
	public Light queryLightByLightNumAndPanId(String panId, String lightNum) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightByLightNumAndPanId(panId,lightNum);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public int changeOnlineStateByDtuId(Long dtuId, Integer onlineState) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.changeOnlineStateByDtuId(dtuId, onlineState);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return -1;
	}

	@Override
	public int updateLightLocation(Light light) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.updateLightLocation(light);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return -1;
	}

	@Override
	public boolean changeLightNum(Integer lightId, String lightNum) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.changeLightNum(lightId, lightNum);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public LightInfoBean queryLightInfoById(Integer lightId) {
		SqlSession sqlSession = getSqlSession();
		try {
			LightMapper operation = sqlSession.getMapper(LightMapper.class);
			return operation.queryLightInfoById(lightId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

}
